




/*
'===============================================================================
'  HNG.Portal.BL.TblHinhAnhSanPhamManagerBase
'===============================================================================
*/

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using HNG.Portal.BLL;
using HNG.Portal.DAL;
using HNG.Portal.DAL.EntityClasses;
using HNG.Portal.DAL.FactoryClasses;
using HNG.Portal.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;
using System.Windows.Forms;
namespace HNG.Portal.BLL
{
	public class TblHinhAnhSanPhamManagerBase
	{
	    
		#region ColumnNames
		
				public const String Field_Id="Id";
				
				public const String Field_IdsanPham="IdsanPham";
				
				public const String Field_Image="Image";
				
				public const String Field_MoTa="MoTa";
				
				public const String Field_TrangThai="TrangThai";
				
		#endregion	
		/// <summary>
		/// Purpose: Class constructor.
		/// </summary>
		public TblHinhAnhSanPhamManagerBase()
		{
			// Nothing for now.
		}
		public DataTable Clone()
		{
			DataTable dt = new DataTable();
						
			
			dt.Columns.Add(Field_Id,typeof(int));
			
						
			
			dt.Columns.Add(Field_IdsanPham,typeof(int));
			
						
			
			dt.Columns.Add(Field_Image,typeof(string));
			
						
			
			dt.Columns.Add(Field_MoTa,typeof(string));
			
						
			
			dt.Columns.Add(Field_TrangThai,typeof(bool));
			
			            
            return dt;			
		}
			
		public TblHinhAnhSanPhamEntity Convert_Entity(TblHinhAnhSanPhamEntity _TblHinhAnhSanPhamEntity,TblHinhAnhSanPhamEntity _TblHinhAnhSanPhamEntity_XML)
		{	
			
				
			_TblHinhAnhSanPhamEntity.Id= _TblHinhAnhSanPhamEntity_XML.Id;
				
			_TblHinhAnhSanPhamEntity.IdsanPham= _TblHinhAnhSanPhamEntity_XML.IdsanPham;
				
			_TblHinhAnhSanPhamEntity.Image= _TblHinhAnhSanPhamEntity_XML.Image;
				
			_TblHinhAnhSanPhamEntity.MoTa= _TblHinhAnhSanPhamEntity_XML.MoTa;
				
			_TblHinhAnhSanPhamEntity.TrangThai= _TblHinhAnhSanPhamEntity_XML.TrangThai;
				
			
			return _TblHinhAnhSanPhamEntity;
		}	
		
			
		public void InsertCollection(EntityCollection _Collection)
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
            {
                adapter.SaveEntityCollection(_Collection);
            }
		}

		public TblHinhAnhSanPhamEntity Insert(TblHinhAnhSanPhamEntity TblHinhAnhSanPhamEntity)
		{
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.SaveEntity(TblHinhAnhSanPhamEntity, true);
			}
			return TblHinhAnhSanPhamEntity;
		}

		
		public TblHinhAnhSanPhamEntity Insert(int Id, int IdsanPham, string Image, string MoTa, bool TrangThai)
		{
			TblHinhAnhSanPhamEntity _TblHinhAnhSanPhamEntity = new TblHinhAnhSanPhamEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_TblHinhAnhSanPhamEntity.Id = Id;
				_TblHinhAnhSanPhamEntity.IdsanPham = IdsanPham;
				_TblHinhAnhSanPhamEntity.Image = Image;
				_TblHinhAnhSanPhamEntity.MoTa = MoTa;
				_TblHinhAnhSanPhamEntity.TrangThai = TrangThai;
				adapter.SaveEntity(_TblHinhAnhSanPhamEntity, true);
			}
			return _TblHinhAnhSanPhamEntity;
		}

		public TblHinhAnhSanPhamEntity Insert(int IdsanPham, string Image, string MoTa, bool TrangThai)
		{
			TblHinhAnhSanPhamEntity _TblHinhAnhSanPhamEntity = new TblHinhAnhSanPhamEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_TblHinhAnhSanPhamEntity.IdsanPham = IdsanPham;
				_TblHinhAnhSanPhamEntity.Image = Image;
				_TblHinhAnhSanPhamEntity.MoTa = MoTa;
				_TblHinhAnhSanPhamEntity.TrangThai = TrangThai;
				adapter.SaveEntity(_TblHinhAnhSanPhamEntity, true);
			}
			return _TblHinhAnhSanPhamEntity;
		}

		public bool Update(TblHinhAnhSanPhamEntity _TblHinhAnhSanPhamEntity)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				RelationPredicateBucket filter = new RelationPredicateBucket();
				IPredicateExpression _PredicateExpression = new PredicateExpression();
				_PredicateExpression.Add(TblHinhAnhSanPhamFields.Id == _TblHinhAnhSanPhamEntity.Id);
					
				filter.PredicateExpression.Add(_PredicateExpression);

				adapter.UpdateEntitiesDirectly(_TblHinhAnhSanPhamEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}
		
		public bool Update(TblHinhAnhSanPhamEntity _TblHinhAnhSanPhamEntity, RelationPredicateBucket filter)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.UpdateEntitiesDirectly(_TblHinhAnhSanPhamEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}

		public bool Update(int Id, int IdsanPham, string Image, string MoTa, bool TrangThai)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblHinhAnhSanPhamEntity _TblHinhAnhSanPhamEntity = new TblHinhAnhSanPhamEntity(Id);
				if (adapter.FetchEntity(_TblHinhAnhSanPhamEntity))
				{
				
					_TblHinhAnhSanPhamEntity.IdsanPham = IdsanPham;
					_TblHinhAnhSanPhamEntity.Image = Image;
					_TblHinhAnhSanPhamEntity.MoTa = MoTa;
					_TblHinhAnhSanPhamEntity.TrangThai = TrangThai;
					adapter.SaveEntity(_TblHinhAnhSanPhamEntity, true);
					toReturn = true;
				}
			}
			return toReturn;
		}

		public bool Delete(int Id)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblHinhAnhSanPhamEntity _TblHinhAnhSanPhamEntity = new TblHinhAnhSanPhamEntity(Id);
				if (adapter.FetchEntity(_TblHinhAnhSanPhamEntity))
				{
					adapter.DeleteEntity(_TblHinhAnhSanPhamEntity);
					toReturn = true;
				}
			}
			return toReturn;
		}
		
		public void DeleteAll() 
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.DeleteEntitiesDirectly("TblHinhAnhSanPhamEntity", null);
			}
		}
		
		
		public int DeleteById(int Id)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblHinhAnhSanPhamFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblHinhAnhSanPhamEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByIdsanPham(int IdsanPham)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblHinhAnhSanPhamFields.IdsanPham == IdsanPham);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblHinhAnhSanPhamEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByImage(string Image)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblHinhAnhSanPhamFields.Image == Image);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblHinhAnhSanPhamEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByMoTa(string MoTa)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblHinhAnhSanPhamFields.MoTa == MoTa);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblHinhAnhSanPhamEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByTrangThai(bool TrangThai)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblHinhAnhSanPhamFields.TrangThai == TrangThai);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblHinhAnhSanPhamEntity", filter);
			}
			return toReturn;
		}
		

		
		public TblHinhAnhSanPhamEntity SelectOne(int Id)
		{
			TblHinhAnhSanPhamEntity toReturn = null;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblHinhAnhSanPhamEntity _TblHinhAnhSanPhamEntity = new TblHinhAnhSanPhamEntity(Id);
				if (adapter.FetchEntity(_TblHinhAnhSanPhamEntity))
				{
					toReturn = _TblHinhAnhSanPhamEntity;
				}
			}
			return toReturn;
		}

		// Return EntityCollection
		public EntityCollection SelectAll()
		{
			EntityCollection _TblHinhAnhSanPhamCollection = new EntityCollection( new TblHinhAnhSanPhamEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblHinhAnhSanPhamCollection, null, 0, null);
			}
			return _TblHinhAnhSanPhamCollection;
		}
		
		// Return DataTable
		public DataTable SelectAllRDT()
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblHinhAnhSanPhamCollection = new EntityCollection(new TblHinhAnhSanPhamEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblHinhAnhSanPhamCollection.EntityFactoryToUse.CreateFields(), toReturn, null, true);
			}
			return toReturn;
		}

		
		// Return EntityCollection
		public EntityCollection SelectById(int Id)
		{
			EntityCollection _TblHinhAnhSanPhamCollection = new EntityCollection(new TblHinhAnhSanPhamEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblHinhAnhSanPhamFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblHinhAnhSanPhamCollection, filter, 0, null);
			}
			return _TblHinhAnhSanPhamCollection;
		}
		
		// Return DataTable
		public DataTable SelectByIdRDT(int Id)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblHinhAnhSanPhamCollection = new EntityCollection(new TblHinhAnhSanPhamEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblHinhAnhSanPhamFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblHinhAnhSanPhamCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByIdsanPham(int IdsanPham)
		{
			EntityCollection _TblHinhAnhSanPhamCollection = new EntityCollection(new TblHinhAnhSanPhamEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblHinhAnhSanPhamFields.IdsanPham == IdsanPham);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblHinhAnhSanPhamCollection, filter, 0, null);
			}
			return _TblHinhAnhSanPhamCollection;
		}
		
		// Return DataTable
		public DataTable SelectByIdsanPhamRDT(int IdsanPham)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblHinhAnhSanPhamCollection = new EntityCollection(new TblHinhAnhSanPhamEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblHinhAnhSanPhamFields.IdsanPham == IdsanPham);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblHinhAnhSanPhamCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByImage(string Image)
		{
			EntityCollection _TblHinhAnhSanPhamCollection = new EntityCollection(new TblHinhAnhSanPhamEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblHinhAnhSanPhamFields.Image == Image);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblHinhAnhSanPhamCollection, filter, 0, null);
			}
			return _TblHinhAnhSanPhamCollection;
		}
		
		// Return DataTable
		public DataTable SelectByImageRDT(string Image)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblHinhAnhSanPhamCollection = new EntityCollection(new TblHinhAnhSanPhamEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblHinhAnhSanPhamFields.Image == Image);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblHinhAnhSanPhamCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByMoTa(string MoTa)
		{
			EntityCollection _TblHinhAnhSanPhamCollection = new EntityCollection(new TblHinhAnhSanPhamEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblHinhAnhSanPhamFields.MoTa == MoTa);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblHinhAnhSanPhamCollection, filter, 0, null);
			}
			return _TblHinhAnhSanPhamCollection;
		}
		
		// Return DataTable
		public DataTable SelectByMoTaRDT(string MoTa)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblHinhAnhSanPhamCollection = new EntityCollection(new TblHinhAnhSanPhamEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblHinhAnhSanPhamFields.MoTa == MoTa);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblHinhAnhSanPhamCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByTrangThai(bool TrangThai)
		{
			EntityCollection _TblHinhAnhSanPhamCollection = new EntityCollection(new TblHinhAnhSanPhamEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblHinhAnhSanPhamFields.TrangThai == TrangThai);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblHinhAnhSanPhamCollection, filter, 0, null);
			}
			return _TblHinhAnhSanPhamCollection;
		}
		
		// Return DataTable
		public DataTable SelectByTrangThaiRDT(bool TrangThai)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblHinhAnhSanPhamCollection = new EntityCollection(new TblHinhAnhSanPhamEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblHinhAnhSanPhamFields.TrangThai == TrangThai);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblHinhAnhSanPhamCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		

	}
}
